#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   user_manage.py
@Time    :   2024-08-05 21:20:42
@Author  :   chakcy 
@Email   :   947105045@qq.com
@description   :   用户管理相关接口
'''

from fastapi import APIRouter, Depends, Security, Request
from ..models import CommonResponseModel
from ..models.common import Page
from ..service import UserManageService
from ..dependencies.redis import RedisDependency
from ..dependencies.jwt import Authorization

router = APIRouter(prefix="/user/manage", tags=["user-manage-controller"])

@router.post("/list", summary="获取用户列表", 
            description="获取系用户列表",
            response_model=CommonResponseModel)
async def get_user_list(page: Page,
                        request: Request,
                        token: str = Security(Authorization),
                        redis: RedisDependency = Depends()):
    return await UserManageService.get_user_list(request=request, 
                                                 redis=redis,
                                                 page=page)

@router.get("/id/{user_id}", summary="根据ID获取用户信息",
            description="根据ID获取用户信息",
            response_model=CommonResponseModel)
async def get_user_by_id(user_id: str,
                         request: Request,
                         token: str = Security(Authorization),
                         redis: RedisDependency = Depends()):
    return await UserManageService.get_user_by_id(request=request, 
                                                  redis=redis,
                                                  user_id=user_id)

@router.get("/name/{user_name}", summary="根据用户名获取用户信息", 
            description="根据用户名获取用户信息", 
            response_model=CommonResponseModel)
async def get_user_by_name(user_name: str,
                           request: Request,
                           token: str = Security(Authorization),
                           redis: RedisDependency = Depends()):
    return await UserManageService.get_user_by_name(request=request, 
                                                    redis=redis,
                                                    userName=user_name)

@router.post("/name/list/", summary="根据用户名模糊查询用户列表",
            description="根据用户名模糊查询用户列表",
            response_model=CommonResponseModel)
async def get_users_by_name_like(user_name: str,
                                 page: Page,
                                 request: Request,
                                 token: str = Security(Authorization),
                                 redis: RedisDependency = Depends()):
    return await UserManageService.get_users_by_name(request=request,
                                                     redis=redis,
                                                     userName=user_name,
                                                     page=page)

@router.get("delete/{user_id}", summary="删除用户",
            description="删除用户",
            response_model=CommonResponseModel)
async def delete_user(user_id: str,
                      request: Request,
                      token: str = Security(Authorization),
                      redis: RedisDependency = Depends()):
    return await UserManageService.delete_user(request=request,
                                               redis=redis,
                                               user_id=user_id)
